<template>
    <el-dialog :title="!dataForm.id ? '新增接口' : '修改接口'" :close-on-click-modal="false" :visible.sync="visible" center>

        <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()"
            label-width="100px">
            <el-form-item label="接口名称" prop="apiName">
                <el-input v-model="dataForm.apiName" placeholder="请输入接口名称"></el-input>
            </el-form-item>
            <el-form-item label="接口url" prop="apiUrl">
                <el-input v-model="dataForm.apiUrl" placeholder="请输入接口url"></el-input>
            </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button @click="visible = false">取消</el-button>
            <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
        </span>
    </el-dialog>
</template>
  
<script>

export default {
    data() {
        return {
            visible: false,
            permissionTreeDialogVisible: false,
            dataForm: {
                id: null,
                apiName: '',
                apiUrl: ''
            },
            dataRule: {
                apiName: [
                    { required: true, message: '接口名称不能为空', trigger: 'blur' }
                ],
                apiUrl: [
                    { required: true, message: '接口url不能为空', trigger: 'blur' }
                ]
            }
        }
    },
    methods: {
        init(data) {
            console.log(data);
            if (data) {
                this.dataForm = data;
            }
            this.visible = true
        },
        // 表单提交
        dataFormSubmit() {
            this.$refs['dataForm'].validate((valid) => {
                if (valid) {
                    this.$http({
                        url: this.dataForm.id ? '/pms/admin/api/updateApi' : '/pms/admin/api/addApi',
                        method: 'post',
                        data: {
                            'id': this.dataForm.id,
                            'apiName': this.dataForm.apiName,
                            'apiUrl': this.dataForm.apiUrl
                        }
                    }).then((response) => {
                        if (response && response.code == "0") {
                            this.$message({
                                message: '操作成功',
                                type: 'success',
                                duration: 1500,
                                onClose: () => {
                                    this.visible = false
                                    this.$emit('refreshDataList')
                                }
                            })
                        } else {
                            this.$message.error(response.message)
                        }
                    })
                }
            })
        },
        permissionTreeDialogHandle(parentId) {
            console.log(parentId)
            if (parentId) {
                console.log(true)
            }
            this.permissionTreeDialogVisible = true;
            console.log(this.permissionTreeDialogVisible);
            this.$nextTick(() => {
                this.$refs.permissionTreeDialog.init(parentId)
            })
        },
        refreshParentNode(nodeInfo) {
            console.log("接收到的消息 ：")
            console.log(nodeInfo)
            this.dataForm.parentId = nodeInfo.id;
        }
    }
}
</script>
  